
#ifndef   __RF12B_H_
#define   __RF12B_H_


#define   RECEIVE_BUFFER_SIZE		64

typedef struct
{
		unsigned char Destination_ID[8];
		unsigned char Source_ID[8];
		unsigned char RF_Command[RECEIVE_BUFFER_SIZE];
}RF_DATA;


extern RF_DATA RF_DataReceived;

#define	BAND		 			0x80D8  	// enable register and FIFO buf.,433MHz,12.5pF   

#define  TURN_ON_CRYSTAL 	0x820C  	// Turn on crystal,!PA, enable receive			   
#define  FREQUENCY			0xA640  	// 432.925MHz									   
#define  BIT_RATE				0xC647  	//	10000000/29/(R+1)/(1+cs*7)								   

#define  REC_CNTRL			0x94C0  	//VDI output, FAST,134kHz,0dBm,-103dBm  

#define  DATA_FILTER			0xC2AC  	// Enable clock recovery auto-lock						   

#define  RESET_FIFO			0xCA80  										   

#define  SET_FIFO				0xCA83  	//FIFO8,SYNC,						   
//#define  SET_FIFO				0xCA87  	//FIFO8,SYNC,						   

#define  AFC					0xC4F7	// Keep offset when VDi hi  										   

#define  DEV_POW				0x9820  //!mp,Dev=30KHz, Pout=-6dBm //0x9810=30kHz,MAX OUT		   
#define  NOP_					0xE000  //NOT USE				
#define  PLL					0xCC67 			   
#define  DUTY_CYCLE			0xC80E  //NOT USE							   
//#define  DUTY_CYCLE			0xC800  //NOT USE							   
#define  SPI_CLK_BAT_DET	0xC003  //1.0MHz,2.2V     //  Vlovbat = 2.2 + V * 0.1, where V - 4 LS bits                

// =========

#define   LOW_BAT				(1<<10)

#define  OPEN_PA				0x822C 
#define  TRANSMIT_ENA		0x823C
#define  RECEIVE_ENA 		0x82DC
#define  CLOSE_PA				TURN_ON_CRYSTAL

#define  WRITE_TO_TRANSMIT	0xB8 
#define  GET_STATUS 			0

#define	READ_FIFO			0xB000

#define  TRANSMIT				1
#define  RECEIVE				0 	 

void RF_Init(void);
void RF_TXD( const unsigned char* Buffer);	  /* put the Data into TransmitBuffer and get the data from ReceiveBuffer */
void RF_RXD (void);

unsigned int RF_SendCommand ( unsigned int Command );
void Drive_RF ( void );

//extern bank1 unsigned char ReceiveBuffer[RECEIVE_BUFFER_SIZE];
extern unsigned char* RF_ReceiveBuffer;
//extern bank1 unsigned char TransmitBuffer[20];
extern bit RF_ReceiveComplete;
extern bit RF_Receive_Command;
extern bit RF_Receive_Answer;
extern bit RF_Receive_MyID;
extern bit RF_Receive_Broadcast;

extern  unsigned int RF_Status;



#endif
